<template>
  <div class="navbar" :class="{ 'is-fixed': isFixed }">
    <div class="container">
      <div class="prama-title">{{ title }}</div>
      <div class="prama-info">
        <a href="">概述</a><span>|</span> <a href="">参数</a><span>|</span>
        <a href="">用户评价</a>
        <slot name="buy"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: '小米11'
    }
  },
  data () {
    return {
      isFixed: false
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      const pagey =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop
      // eslint-disable-next-line no-unneeded-ternary
      this.isFixed = pagey > 152 ? true : false
    }
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll, false)
  }
}
</script>

<style lang="scss" scoped>
@import './../assets/scss/mixin.scss';
@import './../assets/scss/config.scss';
.navbar {
  height: 70px;
  line-height: 70px;
  background-color: $colorG;
  z-index: 10;
  &.is-fixed {
    position: fixed;
    top: 0;
    width: 100%;
    box-shadow: 0 5px 5px $colorE;
  }
  .container {
    border-top: 1px solid $colorH;
    @include flex();

    .prama-title {
      color: $colorI;
      font-size: $fontJ;
      font-weight: bold;
    }

    .prama-info {
      a {
        font-size: $fontK;
        margin-right: 8px;
        color: $colorI;
        &:hover {
          color: $colorA;
        }
      }

      span {
        margin-right: 6px;
      }

      slot {
      }
    }
  }
}
</style>
